//道达快递的物品选择js片断 by liangcaijian @qq 632324010
function reload() {
    window.location.reload();
}
function checkDiv() {
	if ($('#tabAuto').css("display") == "none" && $('#tabHand').css("display") == "block") {
		$("#tabAuto").css('display','block');
		$("#tabHand").css('display','none');
	}else{
		$("#tabAuto").css('display','none');
		$("#tabHand").css('display','block'); 
	}	

}
//手动填写物品名称拼接
function fillgoodsname1(wpdl, wpxl, wppm, wppp, wpsl, wpdj, gn) {
    var ddl2 = document.getElementById(wpdl);
    var ddl3 = document.getElementById(wpxl);
    var ddl4 = document.getElementById(wppm); var ddl44 = document.getElementById(wppp);
    var ddl5 = document.getElementById(wpsl);
    var dj = document.getElementById(wpdj);
	if ($('#'+wpdl).val() == "") { alert("请填写大类"); $('#'+wpdl).focus(); return false; }
    if ($('#'+wpxl).val() == "") { alert("请填写小类"); $('#'+wpxl).focus(); return false; }
	if ($('#'+wppm).val() == "") { alert("请填写品名"); $('#'+wppm).focus(); return false; }

    if ($('#'+wpsl).val() == "0" || $('#'+wpsl).val() == "") {
        alert("请填写数量"); $('#'+wpsl).focus(); return false;
    } else {
        try {
            document.getElementById('count').value = parseInt(document.getElementById('count').value);
            if (document.getElementById('count').value == 'NaN') {
                alert('输入数量有误');
                document.getElementById('count').value = '';
                document.getElementById('count').focus();
                return false;
            }
        }
        catch (ex) {
            alert('输入数量有误');
            document.getElementById('count').value = '';
            document.getElementById('count').focus();
            return false;
        }
    }	
    if (dj.value == "0" || dj.value == "") {
        alert("请填写单价");
        dj.focus();
        return false;
    } else {
        try {
            document.getElementById('Text1').value = parseInt(document.getElementById('Text1').value);
            if (document.getElementById('Text1').value == 'NaN') {
                alert('输入单价有误');
                document.getElementById('Text1').value = '';
                document.getElementById('Text1').focus();
                return false;
            }
        }
        catch (ex) {
            alert('输入单价有误');
            document.getElementById('Text1').value = '';
            document.getElementById('Text1').focus();
            return false;
        }
    }

    if (document.getElementById(gn).value == '') {
        s = ddl44.value + ' ' + ddl4.value + ' ' + ddl3.value + '*' + ddl5.value;
    } else {
        s = " " + ddl44.value + ' ' + ddl4.value + ' ' + ddl3.value + '*' + ddl5.value; //ddl5.options[ddl5.selectedIndex].text
    }
    if (s.indexOf("请选择") <= 0) {
        document.getElementById(gn).value += s;
        try {
            document.getElementById('GoodsCount').value = parseInt(document.getElementById('GoodsCount').value) + parseInt(ddl5.value);
        } catch (ex) {
        }
    } else {
        ddl2.value = "";
        ddl3.value = "";
        ddl4.value = "";
        ddl44.value = "";
        ddl5.value = "";
        document.getElementById(gn).value = "";
    }
}
//手动填写物品名称重置
function ResetWplb2(d2, d3, d4, d5, d6, d7) {
    $('#'+d2).val('');
	$('#'+d3).val('');
	$('#'+d4).val('');
	$('#'+d5).val('');
	$('#'+d6).val('');
	$('#'+d7).val('');
}

//选择物品名称拼接
function fillgoodsname(wplbdalei, wplbxiaolei, wplbpinming, wplbpinpai, wplbcount, gn) {
    var ddl1 = document.getElementById(wplbdalei);
    var ddl2 = document.getElementById(wplbxiaolei);
    var ddl3 = document.getElementById(wplbpinming);
    var ddl33 = document.getElementById(wplbpinpai);
    var ddl4 = document.getElementById(wplbcount);
    var smalls = document.getElementById("txtSmallType");    //手输小类
    var gname = document.getElementById("txtGName");        //手输品名
    var brand = document.getElementById("txtGBrand");       //手输品牌
    var s = '';
    var ssort = '';
    if (ddl4.value != "" && ddl4.value != "0") {
        if (ddl1 != null) {
            if (ddl1.options[ddl1.selectedIndex].value == "-99") {
                s = " " + brand.value + " " + gname.value + " " + smalls.value;
                ssort = brand.value + "," + gname.value + "," + ddl4.value;
            }
            else if (ddl1.options[ddl1.selectedIndex].text.indexOf("请选择") <= 0) {
                if (ddl2 != null) {
                    if (ddl2.options[ddl2.selectedIndex].value == "-99") {
                        s = " " + brand.value + " " + gname.value + " " + smalls.value;
                        ssort = brand.value + "," + gname.value + "," + ddl4.value;
                    }
                    else if (ddl2.options[ddl2.selectedIndex].text.indexOf("请选择") <= 0) {
                        if (ddl3 != null) {
                            if (ddl3.options[ddl3.selectedIndex].value == "-99") {
                                s = " " + brand.value + " " + gname.value + " " + ddl2.options[ddl2.selectedIndex].text;
                                ssort = brand.value + "," + gname.value + "," + ddl4.value;
                            }
                            else if (ddl3.options[ddl3.selectedIndex].text.indexOf("请选择") <= 0) {
                                if (ddl33 != null) {
                                    if (ddl33.options[ddl33.selectedIndex].value == "-99") {
                                        s = " " + brand.value + " " + ddl3.options[ddl3.selectedIndex].text + " " + ddl2.options[ddl2.selectedIndex].text;
                                        ssort = brand.value + "," + ddl3.options[ddl3.selectedIndex].text + "," + ddl4.value;
                                    }
                                    else if (ddl33.options[ddl33.selectedIndex].text.indexOf("请选择") <= 0) {
                                        s += " " + ddl33.options[ddl33.selectedIndex].text;
                                        s += " " + ddl3.options[ddl3.selectedIndex].text;
                                        s += " " + ddl2.options[ddl2.selectedIndex].text;
                                        ssort = ddl33.options[ddl33.selectedIndex].text + "," + ddl3.options[ddl3.selectedIndex].text + "," + ddl4.value;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        s += '*' + ddl4.value;
        if (s.indexOf("请选择") <= 0) {
            document.getElementById(gn).value += s;
            var tax = document.getElementById('lbltax').value;
            var dj = 0;
            try {
                dj = parseInt(document.getElementById('wplbworth').value);
            }
            catch (ex) {
                dj = 0;
            }
            try {
                document.getElementById('GoodsCount').value = parseInt(document.getElementById('GoodsCount').value) + parseInt(ddl4.value);
            } catch (ex) {
            }
        }else {
            if (ddl1 != null) {
                ddl1.value = "-1";
            }
            if (ddl2 != null) {
                for (var i = 0; i < ddl2.options.length; i++) {
                    ddl2.options.remove(i);
                    i--;
                }
            }
            if (ddl3 != null) {
                for (var i = 0; i < ddl3.options.length; i++) {
                    ddl3.options.remove(i);
                    i--;
                }
            }
            document.getElementById(gn).value = "";
            document.getElementById('GoodsCount').value = "";
            document.getElementById('GoodsWorth').value = "";
            document.getElementById('lbltax').value = "";
            alert("选择类别有误,请正确选择类别");
        }
    }
}

//选择物品名称重置
function ResetWplb1(wplbdalei, wplbxiaolei, wplbpinming, wplbpinpai, wplbcount, wplbworth) {
    if (document.getElementById("txtBigType") != null && document.getElementById("txtBigType") != undefined) {
        document.getElementById("txtBigType").value = "";  //手输大类
        document.getElementById("txtBigType").style.display = "none";
    }
    if (document.getElementById("txtSmallType") != null && document.getElementById("txtSmallType") != undefined) {
        document.getElementById("txtSmallType").value = "";  //手输小类
        document.getElementById("txtSmallType").style.display = "none";
    }
    if (document.getElementById("txtGName") != null && document.getElementById("txtGName") != undefined) {
        document.getElementById("txtGName").value = "";      //手输品名
        document.getElementById("txtGName").style.display = "none";
    }
    if (document.getElementById("txtGBrand") != null && document.getElementById("txtGBrand") != undefined) {
        document.getElementById("txtGBrand").value = "";     //手输品牌
        document.getElementById("txtGBrand").style.display = "none";
    }
    var ddl1 = document.getElementById(wplbdalei);
    var ddl1 = document.getElementById(wplbdalei);
    var ddl2 = document.getElementById(wplbxiaolei);
    var ddl3 = document.getElementById(wplbpinming);
    var ddl33 = document.getElementById(wplbpinpai);
    var ddl4 = document.getElementById(wplbcount);
    var ddl5 = document.getElementById(wplbworth);
    if (ddl1 != null) {
        ddl1.value = "-1";
    }
    if (ddl2 != null) {
		for (var i1 = 0; i1 < ddl2.options.length; i1++) {
            ddl2.options.remove(i1);
            i1--;
        }
    }
    if (ddl3 != null) {
        for (var ii = 0; ii < ddl3.options.length; ii++) {
            ddl3.options.remove(ii);
            ii--;
        }
    } if (ddl33 != null) {
        for (var iii = 0; iii < ddl33.options.length; iii++) {
            ddl33.options.remove(iii);
            iii--;
        }
    }
    ddl4.value = "0";
    ddl5.value = "0";
}


//物品名称拼接验证
function checkAdd() {
    var ddl1 = document.getElementById("wplbdalei");        //大类
    var ddl2 = document.getElementById("wplbxiaolei");      //小类
    var ddl3 = document.getElementById("wplbpinming");       //品名
    var ddl5 = document.getElementById("wplbpinpai");      //品牌
    var big = document.getElementById("txtBigType");        //手输大类
    var small = document.getElementById("txtSmallType");    //手输小类
    var gname = document.getElementById("txtGName");        //手输品名
    var brand = document.getElementById("txtGBrand");       //手输品牌
    var ddl4 = document.getElementById("wplbcount");
    var s = document.getElementById("wplbworth");
    if (ddl1 != null) {
        if (ddl1.value == "-99") {
            if (big.value.trim() == "") {
                alert("请输入大类");
                big.focus();
                return false;
            }
            if (small.value.trim() == "") {
                alert("请输入小类");
                small.focus();
                return false;
            }
            if (gname.value.trim() == "") {
                alert("请输入品名");
                gname.focus();
                return false;
            }
            if (brand.value.trim() == "") {
                alert("请输入品牌");
                brand.focus();
                return false;
            }
        } else {
            if (ddl1.value == "" || ddl1.value == "-1") {
                alert("请选择大类");
                ddl1.focus();
                return false;
            }
            if (ddl2 != null) {
                if (ddl2.value == "-99") {
                    if (small.value.trim() == "") {
                        alert("请输入小类");
                        small.focus();
                        return false;
                    }
                    if (gname.value.trim() == "") {
                        alert("请输入品名");
                        gname.focus();
                        return false;
                    }
                    if (brand.value.trim() == "") {
                        alert("请输入品牌");
                        brand.focus();
                        return false;
                    }
                }
                else {
                    if (ddl2.value == "" || ddl2.value == "-1") {
                        alert("请选择小类");
                        ddl2.focus();
                        return false;
                    }
                    if (ddl3 != null) {
                        if (ddl3.value == "-99") {
                            if (gname.value.trim() == "") {
                                alert("请输入品名");
                                gname.focus();
                                return false;
                            }
                            if (brand.value.trim() == "") {
                                alert("请输入品牌");
                                brand.focus();
                                return false;
                            }
                        } else {
                            if (ddl3.value == "" || ddl3.value == "-1") {
                                alert("请选择品名");
                                ddl3.focus();
                                return false;
                            }
                            if (ddl5.value == "-99") {
                                if (brand.value.trim() == "") {
                                    alert("请输入品牌");
                                    brand.focus();
                                    return false;
                                }
                            } else {
                                if (ddl5 != null) {
                                    if (ddl5.value == "" || ddl5.value == "-1") {
                                        alert("请选择品牌");
                                        ddl5.focus();
                                        return false;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    if (ddl4.value == "" || ddl4.value == "0") {
        alert("请填写数量");
        ddl4.focus();
        return false;
    } else {
        try {
            document.getElementById('wplbcount').value = parseInt(document.getElementById('wplbcount').value);
            if (document.getElementById('wplbcount').value == 'NaN') {
                alert('输入数量有误');
                document.getElementById('wplbcount').value = '';
                document.getElementById('wplbcount').focus();
                return false;
            }
        }
        catch (ex) {
            alert('输入数量有误');
            document.getElementById('wplbcount').value = '';
            document.getElementById('wplbcount').focus();
            return false;
        }
    }
    if (s.value == "" || s.value == "0") {
        alert('请填写单价');
        s.focus();
        return false;
    } else {
        try {
            document.getElementById('wplbworth').value = parseInt(document.getElementById('wplbworth').value);
            if (document.getElementById('wplbworth').value == 'NaN') {
                alert('输入单价有误');
                document.getElementById('wplbworth').value = '';
                document.getElementById('wplbworth').focus();
                return false;
            }
        }
        catch (ex) {
            alert('输入单价有误');
            document.getElementById('wplbworth').value = '';
            document.getElementById('wplbworth').focus();
            return false;
        }
    }	
}


function d() {
    try {
        document.getElementById('GoodsWorth').value = parseInt(document.getElementById('GoodsWorth').value) + (parseInt(document.getElementById('Text1').value) * parseInt(document.getElementById('count').value));
    }
    catch (ex) {
        alert('输入有误');
        document.getElementById('Text1').value = 0;
        document.getElementById('count').value = 0;
    }
    if (document.getElementById('GoodsWorth').value == 'NaN') {
        alert('输入有误');
        document.getElementById('GoodsWorth').value = 0;
        document.getElementById('Text1').value = 0;
        document.getElementById('count').value = 0;
    }
}
function c() {
    try {
        document.getElementById('GoodsWorth').value = parseInt(document.getElementById('GoodsWorth').value) + (parseInt(document.getElementById('wplbworth').value) * parseInt(document.getElementById('wplbcount').value));
    }
    catch (ex) {
        alert('输入有误');
        document.getElementById('wplbcount').value = '0';
        document.getElementById('wplbworth').value = '';
        document.getElementById('GoodsCount').value = '';
        return false;
    }
    if (document.getElementById('GoodsWorth').value == 'NaN') {
        alert('输入有误');
        document.getElementById('wplbcount').value = '0';
        document.getElementById('GoodsWorth').value = 0;
        document.getElementById('GoodsCount').value = '';
        document.getElementById('wplbworth').value = ''; return false;
    }
}
